#pragma once

#include "BondChart/bondcharttools.h"
#include <QString>
#include <map>
#include <vector>

#define APRISMT_REQ_30DAY		30	//近30天
#define APRISMT_REQ_HALFYEAR	183	//近半年
#define APRISMT_REQ_YEAR		366	//今年以来

enum em_NewDetail {
	detailModel_Default,
	detailModel_CDC_Aprismt_30Day,		//中债估值：近30天
	detailModel_CDC_Aprismt_HalfYear,	//中债估值：近半年
	detailModel_CDC_Aprismt_Year,		//中债估值：今年以来
	detailModel_CDC_Aprismt_90Day,		//中债估值：近90天
	detailModel_CDC_Aprismt_All,		//请求所有数据
	detailModel_SQS_Aprismt_30Day,		//上清所估值：近30天
	detailModel_SQS_Aprismt_HalfYear,	//上清所估值：近半年
	detailModel_SQS_Aprismt_Year,		//上清所估值：今年以来
	detailModel_ZZ_Aprismt_30Day,		//中证估值：近30天
	detailModel_ZZ_Aprismt_Year,		//中证估值：今年以来
	detailModel_DealCurveKLineCFETS,//CFETS成交曲线日线
	detailModel_DealCurveKLineEx,//交易所成交曲线日线
	detailModel_DealCurveKLineBroker,//broker成交日线
	//detailModel_DealCurveRealTime,//成交曲线实时
	//detailModel_QuoteCurve,//报价曲线
	detailModel_YieldCurve,//收益率曲线

	//信用利差
	detailModel_InterestBond,//个券利差
	detailModel_InterestIssuer,//发行人利差
	//detailModel_EstimateCurve//估值曲线

	detailModel_DealCurveKLineCloseCFETS,//CFETS成交曲线日线（收盘）
	detailModel_DealCurveKLineCloseEx,//交易所成交曲线日线（收盘）
	detailModel_DealCurveKLineCloseBroker,//broker成交日线（收盘）
	detailModel_DealCurveKLineCloseQuote,//broker报价日线（bid，ofr收盘）
};

typedef struct _UnRecommendPriceData
{
	float		m_CleanPrice;										//净价
	float		m_Yield;											//收益率
	float		m_Modified_Duration;								//修正久期
	float		m_Convexity;										//估价凸性 
	float		m_Basis_Point_Value;								//基点价值 
	float		m_Spread_Duration;									// 估价利差久期 
	float		m_Spread_Convexity;									// 估价利差凸性 
	char		m_Credibility[24];									// 可信度
	char		m_cdcExercise[24];									//中债估值行权到期  (0-行权 1-到期)
	_UnRecommendPriceData() :m_CleanPrice(0.0f), m_Yield(0.0f),
		m_Modified_Duration(0.0f), m_Convexity(0.0f), m_Basis_Point_Value(0.0f),
		m_Spread_Duration(0.0f), m_Spread_Convexity(0.0f)
	{
		m_Credibility[0] = '\0';
		m_cdcExercise[0] = '\0';
	};
}_UnRecommendPriceDataType;

class DetailAppraisementPriceData
{
	//将所有数据都保存在一个类中
public:
	_UnRecommendPriceDataType m_UnRecommendData; //非推荐
	xQBCDCPriceSingleHis_c m_RecommendAllData;   //推荐

	DetailAppraisementPriceData() {};
};

class BondAprismtHistoryData
{
public:
	//中债数据
	std::map<unsigned int, DetailAppraisementPriceData> m_CDCPriceCtner;
	//上清所数据
	std::map<unsigned int, DetailAppraisementPriceData> m_SCHPriceCtner;

	std::map<unsigned int, DetailAppraisementPriceData> m_ZZPriceCtner;

	BondAprismtHistoryData() { m_CDCPriceCtner.clear(); m_SCHPriceCtner.clear(); m_ZZPriceCtner.clear(); }

};

class BondDetailChartData;
class BondDetailCache
{
public:
	static BondDetailCache& instance();
	BondDetailChartData& getChart(const std::string& strBondKey);
	bool hasCache(const std::string& strBondKey);

private:
	BondDetailCache();
	~BondDetailCache();

	void eliminateCache();
	void delChart(BondDetailChartData* chart);

private:
	std::map<std::string, BondDetailChartData*> m_mapData;
	std::vector<uint32_t> mTicks;
};

class BondDetailChartData
{
public:
	BondDetailChartData();
	uint32_t tickTime() { return mTick; }
	void updateTick();

	BondAprismtHistoryData* m_pAaprismtHisData = nullptr;//债券估值数据

	xQBABrokerDealKlineDayList_c* m_pDealCurveKLineEx = nullptr;//交易所成交日线
	xQBABrokerDealKlineDayList_c* m_pDealCurveKLineBroker = nullptr;//broker成交日线
	xQBABrokerDealKlineDayList_c* m_pDealCurveKLineCFETS = nullptr;//CFETS成交日线

	xQBBondCreditSpreadAck* m_pInterestBond = nullptr;//个券信用利差
	xQBIssuerCreditSpreadAck* m_pInterestIssuer = nullptr;//主体信用利差
	xQBABrokerKlineDayCloseList_Ack* m_pBrokerDealKlineBrokerDayClose = nullptr;//broker成交日线（收盘）
	xQBABrokerKlineDayCloseList_Ack* m_pDealKlineDayCloseEx = nullptr;//交易所成交日线（收盘）
	xQBABrokerKlineDayCloseList_Ack* m_pCfetsDealKlineCfetsDayClose = nullptr;//CFETS成交日线（收盘）
	xQBABrokerKlineDayCloseBoList_c* m_pKlintDayCloseBoList = nullptr;//报价收盘bid，ofr日线

	CAnalysisYieldCurve* m_pYieldCurve = nullptr;//收益率曲线

private:
	uint32_t mTick;
};

